﻿@using IOA.MES.DataAccess.Enum
@{
    ViewBag.Title = "订单管理";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
}
@section Contents{
    <style>
        .layui-form-label {
            width: auto;
        }

        .layui-table-cell {
            height: auto;
        }
    </style>
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">{{lang.Field.OrderNo}}：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtOrderNo" placeholder="请输入订单号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">{{lang.Field.CustomerInfo}}：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtCustomer" placeholder="如客户代码、客户名称等" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">{{lang.Field.OrderStatus}}：</label>
                        <div class="layui-input-inline">
                            <select id="selStatus" lay-filter="selStatus">
                                <option value="">所有状态</option>
                                <option value="@((int)OrderStatus.New)">待生产</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">{{lang.Field.OrderDate}}：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtRangeDate" placeholder="请选择下单日期" value="@(DateTime.Today.AddMonths(-1).ToString("yyyy-MM-dd")+" 至 "+DateTime.Today.ToString("yyyy-MM-dd"))" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn layuiadmin-btn-list" type="button">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                        <button class="layui-btn layui-btn-normal layuiadmin-btn-list" type="button" onclick="editOrder(0);">
                            <i class="layui-icon layui-icon-addition layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-card">
            <div class="layui-card-body">
                <table id="table" lay-filter="table"></table>
            </div>
        </div>
    </div>
</script>


@section Scripts{
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });
        setTimeout(function () {
            initLayui();
        }, 50);

        function initLayui() {
            layui.use(['table', 'layer', 'form','laydate'], function () {
                var layer = layui.layer,
                    table = layui.table,
                    form = layui.form,
                    laydate = layui.laydate;
                laydate.render({
                    elem: '#txtRangeDate'
                    , range: '至'
                });
                var options = {
                    elem: '#table'
                    , url: '/Plan/QueryOrders'
                    , method: "post"
                    , where: { orderNo: "", customer: "", status: null, startDate: "@DateTime.Today.AddMonths(-1).ToString("yyyy-MM-dd")", endDate: "@DateTime.Today.ToString("yyyy-MM-dd")" }
                    , page: {
                        limit: 15
                        , limits: [15, 20, 25, 30, 40, 50]
                    }
                    , response: {
                        statusName: 'ErrCode'
                        , statusCode: 200
                        , msgName: 'ErrCode'
                        , countName: 'TotalCount'
                        , dataName: 'Data'
                    }
                    , cols: [[
                        { title: '序号', type:"numbers", width: 60 }
                        , { field: 'InnerOrderNo', title: '订单号' }
                        , { field: 'CustomerCode', title: '客户代码' }
                        , { field: 'CustomerName', title: '客户名称' }
                        , { field: 'OrderTimeStr', title: '下单时间' }
                        , { field: 'Remark', title: '备注' }
                        , { field: 'Description', title: '描述' }
                        , {
                            title: '操作', minWidth: 200, templet: function (d) {
                                var str = '<button class="layui-btn layui-btn-sm layui-btn-normal" onclick="editOrder(' + d.PkId + ')"><i class="layui-icon">&#xe642;</i>编辑</button>\
                                           <button class="layui-btn layui-btn-sm layui-btn-warn" onclick="workOrderMgr(\'' + d.InnerOrderNo + '\')"><i class="layui-icon">&#xe621;</i>工单管理</button>';
                                return str;
                            }
                        }
                    ]]
                };

                $("#btnSearch").click(function () {
                    queryTable();
                });
                queryTable();
                function queryTable() {
                    options.page.curr = 1;
                    options.where.orderNo = $("#txtOrderNo").val();
                    options.where.customer = $("#txtCustomer").val();
                    options.where.status = $("#selStatus").val() == "" ? null : parseInt($("#selStatus").val());
                    var rangeTime = $("#txtRangeDate").val().trim() == '' ? new Array() : $("#txtRangeDate").val().trim().split(' 至 ');
                    options.where.startDate = rangeTime.length <= 0 ? null : rangeTime[0];
                    options.where.endDate = rangeTime.length <= 0 ? null : rangeTime[1];

                    if (table.index <= 0) {
                        table.render(options);
                    } else {
                        table.reload("table", options);
                    }
                }
            });
        }

        function editOrder(orderId) {
            layer.open({
                type: 2,
                shade: [0.1, '#000'],
                area: ['550px', '650px'],
                content: "/Plan/EditOrder?orderId=" + orderId,
                end: function () {
                    $("#btnSearch").click();
                }
            });
        }

        function workOrderMgr(orderNo) {
            parent.layui.index.openTabsPage("/Plan/WorkOrderMgr?orderNo=" + orderNo, "工单管理(" + orderNo + ")");
        }
    </script>
}
